package com.co.video.controller;

import com.co.common.entity.Result;
import com.co.video.pojo.VideoState;
import com.co.video.service.VideoStateService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ldl.plus
 * @date 2020年06月22日  0:41
 */

@RestController
@RequestMapping("/videoState")

public class VideoStateController {

    @Autowired
    private VideoStateService videoStateService;

    /**
     * 根据视频aid查询视频详情
     *
     * @param aid 视频id
     * @return
     */
    @GetMapping("/aid/{aid}")
    public Result<VideoState> findByAid(@PathVariable("aid") String aid) {
        VideoState videoState = videoStateService.findByAId(aid);
        return Result.ok(videoState);
    }

    /**
     * TvVideoState分页条件搜索实现
     *
     * @param videoState
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}")
    public Result<PageInfo<VideoState>> findPage(@RequestBody(required = false) VideoState videoState, @PathVariable int page, @PathVariable int size) {
        //调用TvVideoStateService实现分页条件查询TvVideoState
        PageInfo<VideoState> pageInfo = videoStateService.findPage(videoState, page, size);
        return Result.ok(pageInfo);
    }

    /**
     * TvVideoState分页搜索实现
     *
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}")
    public Result<PageInfo<VideoState>> findPage(@PathVariable int page, @PathVariable int size) {
        //调用TvVideoStateService实现分页查询TvVideoState
        PageInfo<VideoState> pageInfo = videoStateService.findPage(page, size);
        return Result.ok(pageInfo);
    }

    /**
     * 多条件搜索品牌数据
     *
     * @param videoState
     * @return
     */
    @PostMapping(value = "/search")
    public Result<List<VideoState>> findList(@RequestBody(required = false) VideoState videoState) {
        //调用TvVideoStateService实现条件查询TvVideoState
        List<VideoState> list = videoStateService.findList(videoState);
        return Result.ok(list);
    }

    /**
     * 根据ID删除品牌数据
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}")
    public Result<?> delete(@PathVariable String id) {
        //调用TvVideoStateService实现根据主键删除
        videoStateService.delete(id);
        return Result.ok();
    }

    /**
     * 修改TvVideoState数据
     *
     * @param videoState
     * @param id
     * @return
     */
    @PutMapping(value = "/{id}")
    public Result<?> update(@RequestBody VideoState videoState, @PathVariable String id) {
        //设置主键值
        videoState.setId(id);
        //调用TvVideoStateService实现修改TvVideoState
        videoStateService.update(videoState);
        return Result.ok();
    }

    /**
     * 新增TvVideoState数据
     *
     * @param videoState
     * @return
     */
    @PostMapping
    public Result<?> add(@RequestBody VideoState videoState) {
        //调用TvVideoStateService实现添加TvVideoState
        videoStateService.add(videoState);
        return Result.ok();
    }

    /**
     * 根据ID查询TvVideoState数据
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<VideoState> findById(@PathVariable String id) {
        //调用TvVideoStateService实现根据主键查询TvVideoState
        VideoState videoState = videoStateService.findById(id);
        return Result.ok(videoState);
    }

    /**
     * 查询TvVideoState全部数据
     *
     * @return
     */
    @GetMapping
    public Result<List<VideoState>> findAll() {
        //调用TvVideoStateService实现查询所有TvVideoState
        List<VideoState> list = videoStateService.findAll();
        return Result.ok(list);
    }
}
